import React, { useReducer } from 'react'

const reducer = (state, action) => {
    console.log(state);
    console.log(action);
    switch (action.type) {
        case "add":
            return {
                num: state.num + 1
            }
        case "sub":
            return {
                num: state.num - 1
            }
        default:
            return state;
    }
}


export default () => {
    const [count, dispatch] = useReducer(reducer, { num: 0 })
    return (
        <div>
            Your counter is {count.num}
            <button onClick={() => { dispatch({ type: "add" }) }}>+</button>
            <button onClick={() => { dispatch({ type: "sub" }) }}>-</button>
        </div>
    )
}
